import {MyHttp} from '../../services/myHttp/myhttp.service';
import { Injectable}  from '@angular/core';
import { PersonalInfo} from '../../services/model/personalInfo';
@Injectable()
export class MyAccountService{
  constructor(private http:MyHttp){

  }

  getInfo():Promise<{status:boolean,data:PersonalInfo}>{
    return this.http.get({
      api:this.http.api.getPersonalInfo
    }).toPromise()
      .then((res)=>{
        let data={
          status:false,
          data:new PersonalInfo()
        };
        if (res.status === 200) {
          let result=res.json();
          data.status=result.status;
          let item=new PersonalInfo();
          item.id=result.data.id;
          item.studentId=result.data.studentId;
          item.name=result.data.name;
          item.gender=result.data.gender;
          item.majorId=result.data.majorId;
          item.major=result.data.major;
          item.gradeId=result.data.gradeId;
          item.gradeName=result.data.gradeName;
          item.birthday=result.data.birthday;
          item.nationId=result.data.nationId;
          item.nation=result.data.nation;
          item.address=result.data.address;
          item.mobile=result.data.mobile;
          item.homePhone=result.data.homePhone;
          data.data=item;
        }
        return Promise.resolve(data);
      })
  }
}

